<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryRef" :inline="true" v-show="showSearch" label-width="68px">
      <el-form-item label="设备名称" prop="repairTime">
        <el-select v-model="queryParams.deviceId" placeholder="请选择设备名称">
          <el-option v-for="dict in deviceNames" :key="dict.deviceId" :label="dict.deviceName"
            :value="dict.deviceId"></el-option>
        </el-select>
      </el-form-item>

      <el-form-item>
        <el-button type="primary" icon="Search" @click="handleQuery">搜索</el-button>
        <el-button icon="Refresh" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>
    <el-table v-loading="loading" :data="daibanList" @selection-change="handleSelectionChange">
      <el-table-column label="序号" type="index" width="55" align="center" />
      <el-table-column label="设备名称" align="center" prop="deviceName" />
      <el-table-column label="领用次数" align="center" prop="makeCnt" />
      <el-table-column label="转移次数" align="center" prop="turnCnt" />
      <el-table-column label="维护次数" align="center" prop="repairCnt" />
    </el-table>

    <pagination v-show="total > 0" :total="total" v-model:page="queryParams.pageNum" v-model:limit="queryParams.pageSize"
      @pagination="getList" />
  </div>
</template>

<script setup name="pandian">
import { listStock } from "@/api/system/stock";
import { listCard } from "@/api/deviceBase/card";
const { proxy } = getCurrentInstance();
const { sxscode } = proxy.useDict('sxscode');

const daibanList = ref([]);
const deviceNames = ref([])
const loading = ref(true);
const showSearch = ref(true);
const total = ref(0);
const receiveTime = ref('')
const data = reactive({
  form: {},
  queryParams: {
    pageNum: 1,
    pageSize: 10,
    startTime: null,
    endTime: null,
  },
  rules: {
  }
});

const { queryParams, form, rules } = toRefs(data);
/** 查询卡片管理列表 */
function getDeviceNames() {
  listCard({
    pageNum: 1,
    pageSize: 1000,
  }).then(response => {
    deviceNames.value = response.rows;
  });
}
/** 查询待办信息列表 */
function getList() {
  loading.value = true;
  listStock(queryParams.value).then(response => {
    daibanList.value = response.rows;
    total.value = response.total;
    loading.value = false;
  });
}

/** 搜索按钮操作 */
function handleQuery() {
  queryParams.value.pageNum = 1;
  getList();
}
onMounted(() => {
  getList();
}),
/** 重置按钮操作 */
function resetQuery() {
  receiveTime.value = ''
  queryParams.value.startTime = null
  queryParams.value.endTime = null
  proxy.resetForm("queryRef");
  handleQuery();
}
const handleSearchTimeChange = (item) => {
  queryParams.value.startTime = item[0]
  queryParams.value.endTime = item[1]
}
getDeviceNames()

</script>
